<%@ page import="java.io.*, java.text.*, java.util.Date, java.sql.*, javax.servlet.*, javax.servlet.http.*, java.util.*" %>
<%
String usernameSC = (String) session.getAttribute("session_name");
String idSC = (String) session.getAttribute("id");
String typeSC = (String) session.getAttribute("type");
if(usernameSC == null || !typeSC.equals("student"))
	response.sendRedirect("error.jsp");


	String id = (String)session.getAttribute("ref_id");
String driver ="com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/projects";
String username = "ia";
String password = "123";
Enumeration variables = request.getParameterNames();

ArrayList names = new ArrayList();
for(int i=0;variables.hasMoreElements();i++)
{
	String name = (String)variables.nextElement();
	names.add(name.substring(2,name.length()));
}

try
{
	Class.forName(driver).newInstance();
	
	Connection connection = DriverManager.getConnection(url, username, password);
	Statement statement = connection.createStatement();
	for(int i=0;i<names.size();i++)
	{
			String query = "insert into join_in values ("+id+","+(String)names.get(i)+")";
			statement.executeUpdate(query);
	}
		response.sendRedirect("index.jsp");
	connection.close();
	
	
}catch(ClassNotFoundException cnfe)
{
		out.println("<br>Couldn't find class file" + cnfe); 
}catch(SQLException sqle)
{
		out.println("<br>SQL Exception: " + sqle);
}catch(InstantiationException ie)
{
		out.println("<br>Instant exception : " + ie);
}catch(IllegalAccessException iae)
{
		out.println("<br>Illegal access exception : " + iae);
}

%>